from typing import Optional, List
from datetime import datetime

from pydantic import BaseModel, EmailStr


# 共享属性
class UserBase(BaseModel):
    email: Optional[EmailStr] = None
    is_active: Optional[bool] = True
    is_superuser: bool = False
    full_name: Optional[str] = None


# 创建用户时需要的属性
class UserCreate(UserBase):
    email: EmailStr
    username: str
    password: str


# 更新用户时可以更新的属性
class UserUpdate(UserBase):
    password: Optional[str] = None
    username: Optional[str] = None


# API响应中的用户信息
class UserResponse(UserBase):
    id: int
    username: str
    created_at: datetime
    updated_at: Optional[datetime] = None
    last_login: Optional[datetime] = None

    class Config:
        from_attributes = True